﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

namespace Cataloger
{
    public static class Serializator
    {
        private static string plikDanych = Path.Combine(Application.StartupPath, "kat.dat");
        public static void Serializuj()
        {
            try
            {
                FileStream myStream = File.Create(plikDanych);
                BinaryFormatter myBinaryFormat = new BinaryFormatter();
                myBinaryFormat.Serialize(myStream, Globalne.KategorieDyn);
                myBinaryFormat.Serialize(myStream, Globalne.KategorieDostepne);
                myBinaryFormat.Serialize(myStream, Globalne.KatalogStartowy);
                myStream.Close();
            }
            catch { }
        }
        public static void Deserializuj()
        {
            try
            {
                FileStream myStream = File.OpenRead(plikDanych);
                BinaryFormatter myBinaryFormat = new BinaryFormatter();
                Globalne.KategorieDyn = (List<KategoriaDynamiczna>)myBinaryFormat.Deserialize(myStream);
                Globalne.KategorieDostepne = (Kategorie)myBinaryFormat.Deserialize(myStream);
                Globalne.KatalogStartowy = (string)myBinaryFormat.Deserialize(myStream);
                myStream.Close();
            }
            catch { }
        }
    }
}
